package com.jzo2o.foundations.controller.operation;

import com.jzo2o.common.model.PageResult;
import com.jzo2o.foundations.model.dto.request.ServePageQueryReqDTO;
import com.jzo2o.foundations.model.dto.request.ServeUpsertReqDTO;
import com.jzo2o.foundations.model.dto.response.ServeResDTO;
import com.jzo2o.foundations.service.IServeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.math.BigDecimal;
import java.util.List;

/**
 * 服务类型相关接口
 *
 * @author itcast
 * @create 2023/7/26 14:16
 **/
@RestController("operationServeController")
@RequestMapping("/operation/serve")
@Api(tags = "运营端 - 区域服务类型相关接口")
public class ServeController {

    @Resource
    private IServeService serveService;

    @GetMapping("/page")
    @ApiOperation("服务类型分页查询")
    public PageResult<ServeResDTO> page(ServePageQueryReqDTO servePageQueryReqDTO){
        PageResult<ServeResDTO> pageResult= serveService.page(servePageQueryReqDTO);
        return pageResult;
    }

    @PostMapping("/batch")
    @ApiOperation("区域服务批量新增")
    public void add(@RequestBody List<ServeUpsertReqDTO> serveUpsertReqDTOList){
        serveService.batchAdd(serveUpsertReqDTOList);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除区域服务开发")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class)
    })
    public void delete(@PathVariable("id") @NotNull(message = "id不能为空") Long id){
        serveService.delete(id);
    }

    @PutMapping("offSale/{id}")
    @ApiOperation("服务下架开发")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "服务id",required = true,dataTypeClass = Long.class)
    })
    public void offSale(@PathVariable("id") @NotNull(message = "id不能为空") Long id){
        serveService.offSale(id);
    }
    @PutMapping("onSale/{id}")
    @ApiOperation("服务上架开发")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "服务id",required = true,dataTypeClass = Long.class)
    })
    public void onSale(@PathVariable("id") @NotNull(message = "id不能为空") Long id){
        serveService.onSale(id);
    }

    @PutMapping("onHot/{id}")
    @ApiOperation("区域服务设置热门")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "服务id",required = true,dataTypeClass = Long.class)
    })
    public void onHot(@PathVariable("id") @NotNull(message = "id不能为空") Long id){
        serveService.onHot(id);
    }
    @PutMapping("offHot/{id}")
    @ApiOperation("区域服务取消设置热门")
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value = "服务id",required = true,dataTypeClass = Long.class)
    })
    public void ofHot(@PathVariable("id") Long id){
        serveService.offHot(id);
    }
    @PutMapping("{id}")
    @ApiOperation("区域服务价格修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "服务id", required = true, dataTypeClass = Long.class),
            @ApiImplicitParam(name = "price", value = "价格", required = true, dataTypeClass = Long.class)
    })
    public void updatePrice(@PathVariable("id") Long id,@RequestParam("price") BigDecimal price){
        serveService.updatePrice(id,price);
    }

}
